/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.fedoraaccess.resourceIndex;

import cz.mzk.kramerius.commons.Dom4jUtils;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.XPath;

/**
 *
 * @author Martin Řehánek <rehan at mzk.cz>
 */
public class RdfParser {

    private static final String FEDORA_PREFIX = "info:fedora/";
    private static final XPath subjectXpath = Dom4jUtils.createXPath("/rdf:RDF/rdf:Description/@rdf:about");

    public List<String> parseSubjects(Document doc) {
        List<Node> nodes = subjectXpath.selectNodes(doc);
        List<String> result = new ArrayList<String>(nodes.size());
        for (Node node : nodes) {
            String prefixed = node.getText();
            String unprefixed = prefixed.substring(FEDORA_PREFIX.length());
            result.add(unprefixed);
        }
        return result;
    }
}
